/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package action;

import static com.opensymphony.xwork2.Action.INPUT;
import static com.opensymphony.xwork2.Action.SUCCESS;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.validator.annotations.VisitorFieldValidator;
import database.AuthenticationDAO;
import database.CustomerDAO;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import model.Customer;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;

    
/**
 *
 * @author Trang
 */
@Namespace("/Administration/Customer")
public class WCustomerAction extends ActionSupport implements ModelDriven<Customer>{
    private List<Customer> customers;
    private Customer customer ;
    private CustomerDAO authenDAO = new CustomerDAO();
//    private int currentPage;
//    private int totalPage;
//    private int itemsPerPage = 10; 
  
    private Map<Integer, String> sorts;
    private Integer sort;
    
    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    
    

    public Map<Integer, String> getSorts() {
        return sorts;
    }

    public void setSorts(Map<Integer, String> sorts) {
        this.sorts = sorts;
    }

   

    public Integer getSort() {
        return sort;
    }

    public void setSort(Integer sort) {
        this.sort = sort;
    }

    public WCustomerAction()
    {
        //customer =new Customer();
        sorts = new HashMap<Integer, String>();
        sorts.put(1, "First Name");
        sorts.put(2, "Last Name");
        sorts.put(3, "Address");
        sorts.put(4, "DOB");
    }
    
    /**
     * @return the customers
     */
    public List<Customer> getCustomers() {
        return customers;
    }

    /**
     * @param customers the customers to set
     */
    public void setCustomers(List<Customer> customers) {
        this.customers = customers;
    }
   
    @Action(value = "sort-customer", results = {
        @Result(name = "success", location = "/manageCustomer/w_customer.jsp")
    })
    public String Sort(){
        //if(sort==1)
        Map session = ActionContext.getContext().getSession();
                session.put("customer", 2);
        customers = authenDAO.getAllCustomer(sort); 
        return SUCCESS;
    }
    @Action(value="viewProfile",
             results = {
                 @Result(name="success", location="/manageMember/w_staffhome.jsp")
             })
     public String AddStaff()
     {
         return SUCCESS;
     }
    @Action(value="add-customer",
             results = {
                 @Result(name="success", location="/manageCustomer/w_addCustomer.jsp")
             })
     public String AddCus()
     {
         return SUCCESS;
     }
    /**
     * @return the currentPage
     */
    

    /**
     * @return the totalPage
     */
    
    @Override
    @VisitorFieldValidator(message = "", appendPrefix = false)
    public Customer getModel() {
        return customer;
    }
}
